<?php

namespace App\Transformers\Frontend;

use App\Models\Category;
use League\Fractal\TransformerAbstract;

class CategoryTransformer extends TransformerAbstract
{

    protected $availableIncludes = ['videos'];

    protected $hidden = ['deleted_at'];

    public function transform(Category $category)
    {
        $category->makeHidden($this->hidden);
        return $category->attributesToArray();
    }

    public function includeVideos(Category $category)
    {
        $videos = $category->videos;
        if (!$videos) {
            return $this->null();
        }
        return $this->collection($videos, new VideoTransformer());
    }
}